/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sim_test;

import javax.swing.*;
import java.awt.Dimension;
import java.awt.*;

/**
 *
 * @author Administrator
 */
public class Sim_JLayeredPaneOverlayHandler extends JLayeredPane{
    
   private Sim_ControllerMain simControllerMain;
   private Sim_JPanelGraphics jPanelGraphics;
   private Sim_JPanelGrid jPanelGrid;    
   private Sim_JPanelBackground jPanelBackground;
   private Dimension dimensionPrefferedSizeOfComponents;
  
   

    public Sim_JLayeredPaneOverlayHandler(Sim_ControllerMain scm, Dimension sizeOfComponents)
    {
        //object creation
        simControllerMain = scm;
        dimensionPrefferedSizeOfComponents = sizeOfComponents;
        jPanelGraphics = new Sim_JPanelGraphics(simControllerMain, new Dimension(dimensionPrefferedSizeOfComponents));
        jPanelGrid = new Sim_JPanelGrid(simControllerMain, new Dimension(dimensionPrefferedSizeOfComponents));
        jPanelBackground = new Sim_JPanelBackground(
                simControllerMain.getCurrentScenario().getSimMap().
                getBackgroundImage(), new Dimension(dimensionPrefferedSizeOfComponents));
        
        //variable change   
        setPreferredSize(dimensionPrefferedSizeOfComponents);
        
        //actions
        setBoundsOfComponents();
        addContent();
        
        
        
    }
    
    private void setBoundsOfComponents()
    {
       int w = (int)dimensionPrefferedSizeOfComponents.getWidth();
       int h = (int)dimensionPrefferedSizeOfComponents.getHeight();
       jPanelBackground.setBounds(0, 0, w, h);
       jPanelGrid.setBounds(0, 0, w, h);
       jPanelGraphics.setBounds(0, 0, w, h);
    }
    
    private void addContent()
    {
       add(jPanelBackground, new Integer(10));
       add(jPanelGrid, JLayeredPane.MODAL_LAYER); // MODAL_LAYER = new Integer(200)
       add(jPanelGraphics, new Integer(300));
        
    }
    
    public void toggleShowGrid()
    {
        if(jPanelGrid.isVisible())
        {
            jPanelGrid.setVisible(false);
        }
        
        else
        {
            jPanelGrid.setVisible(true);
        }
    }
    
    public boolean getGridIsVisible()
    {
        return jPanelGrid.isVisible();
    }
}
